<template>
	<view class="my-upload" @click="upload">
		<image v-if="img" class="bg" :src="img" mode="widthFix"></image>
		<image v-else class="bg" src="../../assets/detail/add-img.png" mode="widthFix"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				img:""
			}
		},
		methods: {
			upload() {
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: 'https://www.example.com/upload', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'user': 'test'
							},
							success: (uploadFileRes) => {
								console.log(uploadFileRes.data);
							}
						});
					}
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
	.my-upload {
		width: 168rpx;
		height: 100%;
		overflow: hidden;

		.bg {
			width: 100%;
			height: 100%;
		}
	}
</style>